package club.hicode.daydayup.zookeeper.distribute2.distribute1;

import cn.hutool.core.thread.ThreadUtil;
import lombok.extern.slf4j.Slf4j;
import org.apache.zookeeper.KeeperException;

import java.io.IOException;
import java.util.concurrent.TimeUnit;

/**
 * xx
 *
 * @author Liu Chunfu
 * @date 2018-06-06 下午5:58
 **/
@Slf4j
public class MainTest {
    public static void main(String[] args) throws Exception {
        for (int i = 0; i < 5; i++) {
            new Thread(() -> {
                ZooDistributeLock zooDistributeLock = new ZooDistributeLock();
                try {
                    //获取锁
                    zooDistributeLock.connection();
                    //创建锁
                    zooDistributeLock.createNode();

                    //获取锁，但是理论上只会有一个才可以获取到，并运行
                    zooDistributeLock.getLock();
                } catch (IOException | InterruptedException | KeeperException e) {
                    e.printStackTrace();
                }
            }).start();
        }
        ThreadUtil.sleep(5, TimeUnit.MINUTES);
    }
}
